// app.js
//app.js
App({
  api: require("/utils/api.js"),
  http: require("/utils/http.js"),

  onLaunch: function () {
 
    let that = this;
    wx.getSystemInfo({
      success: function (res) {

        let menuButton = wx.getMenuButtonBoundingClientRect();
        let titleBarHeight =
          (menuButton.top - res.statusBarHeight) * 2 + menuButton.height;
        that.globalData.safeAreaInsets = res.safeArea.bottom - res.safeArea.height + "rpx"
        that.globalData.headHeight = titleBarHeight * 2 + "rpx";
        that.globalData.headTop = res.statusBarHeight * 2 + "rpx";
        that.globalData.sumHeight =
          titleBarHeight * 2 + res.statusBarHeight * 2 + "rpx";
        that.globalData.screenHeight = res.safeArea.bottom;
      },
    });
  },
  onShow: function () {
    wx.setStorageSync("log", "1");
    if (wx.canIUse("getUpdateManager")) {
      const updateManager = wx.getUpdateManager();
      updateManager.onCheckForUpdate(function (res) {
        console.log("onCheckForUpdate====", res);
        // 请求完新版本信息的回调
        if (res.hasUpdate) {
          console.log("res.hasUpdate====");
          updateManager.onUpdateReady(function () {
            wx.showModal({
              title: "更新提示",
              content: "新版本已经准备好，是否重启应用？",
              success: function (res) {
                console.log("success====", res);
                // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
                if (res.confirm) {
                  // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                  updateManager.applyUpdate();
                }
              },
            });
            return;
          });
          updateManager.onUpdateFailed(function () {
            // 新的版本下载失败
            wx.showModal({
              title: "已经有新版本了哟~",
              content: "新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~",
            });
            return;
          });
        }
      });
    } else {
      //TODO 此时微信版本太低（一般而言版本都是支持的）
      wx.showModal({
        title: "溫馨提示",
        content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。",
      });
    }
    // wx.hideHomeButton();
  },
  globalData: {
    userInfo: null,
    headTop: "",
    headHeight: "",
    sumHeight: "",
    screenHeight: "",
    isUnload: "",
    safeAreaInsets: "",
    isShow: ""
  },
});